<template>
  <div :style="outModuleCss">
    <div class="swiper-section">
      <div :style="moduleBgCss" class="module-bg full-width"></div>
      <div
        class="swiper-box"
        :class="[
          dotsClass,
          propsData.params.swiperType == 2 ? 'fullSwiper' : '',
        ]"
        :style="[moduleCss]"
      >
        <el-carousel
          :style="swiperStyle.style"
          autoplay
          loop
          :height="swiperHeight + 'px'"
          arrow="never"
          :type="swiperStyle.type"
        >
          <el-carousel-item
            v-for="(item, index) in picList"
            :key="index"
            style="height: 100%; border-radius: 10px; overflow: hidden"
          >
            <div
              class="picItem"
              :class="
                propsData.params.bannerList.length == 0 ? 'example-box' : ''
              "
            >
              <img :src="item.picUrl" alt="" />
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
    </div>
  </div>
</template>

<script>
import defaultImg from "@/assets/images/diy/default_img.png";
import { mixinsModuleCss } from "@/components/DiyNew/diy/mixins/index.js";

export default {
  name: "pageHeader",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
  },
  mixins: [mixinsModuleCss],
  data() {
    return {
      dotPosition: "top",
    };
  },
  mounted() {
    console.log("组件挂载了：", this.propsData);
  },
  watch: {},
  computed: {
    swiperStyle() {
      let obj = {
        style: {},
        type: "",
      };
      if (this.propsData.params.swiperType == 1) {
        obj.style = { width: "95%" };
      }
      if (this.propsData.params.swiperType == 2) {
        obj.style = { width: "100%" };
      }
      if (this.propsData.params.swiperType == 3) {
        obj.style = { width: "100%" };
        obj.type = "card";
      }
      return obj;
    },
    dotsClass() {
      let classStr = "";
      if (this.propsData.params.dotsPosition == "left") {
        classStr = "dots-left";
      }
      if (this.propsData.params.dotsPosition == "center") {
        classStr = "";
      }
      if (this.propsData.params.dotsPosition == "right") {
        classStr = "dots-right";
      }
      return classStr;
    },
    picList() {
      if (!this.propsData.params.bannerList.length) {
        return [
          {
            picUrl: defaultImg,
          },
        ];
      } else {
        return this.propsData.params.bannerList;
      }
    },
    swiperHeight() {
      return this.propsData.params.swiperHeight/2 || 146;
    },
  },
  methods: {},
};
</script>

<style lang="scss" scoped>
.swiper-section {
  width: 100%;
  text-align: center;
  position: relative;

  .swiper-box {
    width: 100%;
    background-color: #f2f2f2;
    border-radius: 8px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    justify-content: center;
    box-sizing: content-box;
    overflow: hidden; 
    margin-bottom: 0!important;

    padding: 0 !important;
    .el-carousel {
      ::v-deep .el-carousel__container {
        width: 100%;
        height: 100%;
      }
      ::v-deep.el-carousel-item {
        width: 100%;
        height: 100%;
      }
      ::v-deep .el-carousel__indicators--outside {
        position: absolute;
        bottom: 0px;
      }
    }
    .picItem {
      width: 100%;
      height: 100%;
      border-radius: 10px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .example-box {
      width: 100px;
      height: 77px;
      margin: 20px auto 0;
    }
  }
  .fullSwiper {
    .picItem {
      border-radius: 0px;
    }
    ::v-deep .el-carousel__item {
      border-radius: 0 !important;
    }
  }
  .dots-left {
    ::v-deep .el-carousel__indicators--horizontal {
      bottom: 0;
      left: 0;
      transform: none;
    }
  }
  .dots-right {
    ::v-deep .el-carousel__indicators--horizontal {
      bottom: 0;
      right: 0;
      left: inherit;
      transform: none;
    }
  }
}
.module-bg {
  width: 100%;
  height: 100%;
  z-index: -1;
  position: absolute;
  left: 0;
  top: 0;
}
.full-width {
  width: 100% !important;
  left: 0 !important;
}
</style>
